package com.demo.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo.entity.Course;
import com.demo.entity.CourseExample;
import com.demo.entity.CourseExample.Criteria;
import com.demo.mapper.CourseMapper;
import com.demo.service.CourseService;
@Service
public class CourseServiceImpl implements CourseService{
	@Autowired
	private CourseMapper courseMapper;
	@Override
	public int deleteCourseById(String id) throws Exception {
		return courseMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int updateCourser(Course course) throws Exception {
		return courseMapper.updateByPrimaryKeySelective(course);
	}

	@Override
	public Course selectCourseById(String id) throws Exception {
		return courseMapper.selectByPrimaryKey(id);
	}

	@Override
	public int addCourse(Course course) throws Exception {
		return courseMapper.insert(course);
	}

	@Override
	public List<Course> selectAllCourse(Course course) throws Exception {
		CourseExample example = new CourseExample();
		Criteria createCriteria = example.createCriteria();
		if(course.getId() != null && !"".equals(course.getId())) {
			createCriteria.andIdLike("%"+course.getId()+"%");
		}
		if(course.getCoursename() !=null && !"".equals(course.getCoursename())) {
			createCriteria.andCoursenameLike("%"+course.getCoursename()+"%");
		}
		return courseMapper.selectByExample(example);
	}
	@Override
	public List<Course> selectAllCourseDistinct() throws Exception {
		CourseExample example = new CourseExample();
		example.setDistinct(true);
		return courseMapper.selectByExample(example);
	}

}
